// Tags:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 2e3 + 5, K = 11, inf = 0x3f3f3f3f;
int n, k, u[N], v[N], f[N][K][K][K][K];

inline int getdis(int x, int y) { return std::abs(x - y); }

int dfs(int x, int pos, int a, int b, int c) {
  if (~f[x][pos][a][b][c]) return f[x][pos][a][b][c];
  int res = inf;
  if (a) res = std::min(res, dfs(x, a, 0, b, c) + getdis(pos, a) + 1);
  if (b) res = std::min(res, dfs(x, b, a, 0, c) + getdis(pos, b) + 1);
  if (c) res = std::min(res, dfs(x, c, a, b, 0) + getdis(pos, c) + 1);
  if (x > n) {
    return a == 0 && b == 0 && c == 0 ? 0 : (f[x][pos][a][b][c] = res);
  }
  if (a && b && c) {
    res = std::min(res, dfs(x + 1, v[x], a, b, c) + getdis(pos, u[x]) +
                            getdis(u[x], v[x]) + 2);
    res = std::min(res, dfs(x + 1, a, v[x], b, c) + getdis(pos, u[x]) +
                            getdis(u[x], a) + 2);
    res = std::min(res, dfs(x + 1, b, a, v[x], c) + getdis(pos, u[x]) +
                            getdis(u[x], b) + 2);
    res = std::min(res, dfs(x + 1, c, a, b, v[x]) + getdis(pos, u[x]) +
                            getdis(u[x], c) + 2);

  } else {
    if (!a)
      res = std::min(res, dfs(x + 1, u[x], v[x], b, c) + getdis(pos, u[x]) + 1);
    else if (!b)
      res = std::min(res, dfs(x + 1, u[x], a, v[x], c) + getdis(pos, u[x]) + 1);
    else
      res = std::min(res, dfs(x + 1, u[x], a, b, v[x]) + getdis(pos, u[x]) + 1);
  }
  return f[x][pos][a][b][c] = res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("taxi.in", "r", stdin);
  freopen("taxi.out", "w", stdout);
#endif
#endif

  read(n), read(k);
  for (int i = 1; i <= n; ++i) { read(u[i]), read(v[i]); }
  memset(f, -1, sizeof(f));
  printf("%d", dfs(1, 1, 0, 0, 0));
  return 0;
}